package com.ihmp.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ihmp.model.Tblocks;
@Repository("BlockDao")
public class BlockDaoImpl implements BlockDao{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void saveOrUpdate(Tblocks block) {
		sessionFactory.getCurrentSession().saveOrUpdate(block);
	}

	@Override
	public Tblocks findById(Integer id) {
		 return (Tblocks) sessionFactory.getCurrentSession().get(Tblocks.class, id);
	}

	@Override
	public void delete(Tblocks block) {
		 sessionFactory.getCurrentSession().delete(block);
		
	}

	@Override
	public List<Tblocks> listBlocks() {
		 return (List<Tblocks>) sessionFactory.getCurrentSession().createQuery("from Tblocks ").list();
	}

	@Override
	public List<Tblocks> getBlocksFromHotelId(Integer id) {
		String strQuery = "from Tblocks WHERE HotelId =:HotelID ";
		Query query = sessionFactory.getCurrentSession().createQuery(strQuery);
		query.setParameter("HotelID", id);
		return query.list();
	}

}
